{{$.Importer.Import "github.com/aarondl/opt/null"}}


type Table[Cols columns, Idxs indexes, FKs foreignKeys, U uniques, C checks] struct {
	Schema      string
	Name        string
	Columns     Cols
	Indexes     Idxs
	PrimaryKey  *constraint
	ForeignKeys FKs
	Uniques     U
	Checks      C
	Comment     string
  {{block "table_extra_fields" . -}}
  {{- end}}
}

type columns interface {
  AsSlice() []column
}

type column struct {
	Name      string
	DBType    string
	Default   string
	Comment   string
	Nullable  bool
	Generated bool
	AutoIncr  bool
}

type indexes interface {
  AsSlice() []index
}

type index struct {
	Type    string
	Name    string
	Columns []indexColumn
	Unique  bool
	Comment string
  {{block "index_extra_fields" . -}}
  {{- end}}
}

type indexColumn struct {
	Name         string
	Desc         null.Val[bool]
	IsExpression bool
}

type constraint struct {
	Name    string
	Columns []string
	Comment string
  {{block "constraint_extra_fields" . -}}
  {{- end}}
}

type foreignKeys interface {
  AsSlice() []foreignKey
}

type foreignKey struct {
	constraint
	ForeignTable   string
	ForeignColumns []string
}

type uniques interface {
  AsSlice() []constraint
}

type checks interface {
  AsSlice() []check
}

type check struct {
	constraint
	Expression string
}
